package com.selfdriving.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.selfdriving.BaseApplication;
import com.selfdriving.BaseObjectListAdapter;
import com.selfdriving.R;
import com.selfdriving.bean.Entity;
import com.selfdriving.bean.ScenicSpots;

public class ActivityAmbitusQueryAdapter extends BaseObjectListAdapter
{
	List<? extends Entity> datas = null;
	Context context;
	BaseApplication application;
	FinalBitmap fb;

	public ActivityAmbitusQueryAdapter(BaseApplication mApplication,
			Context context, List<? extends Entity> datas)
	{
		super(mApplication, context, datas);
		this.application = mApplication;
		this.datas = datas;
		this.context = context;
		fb = FinalBitmap.create(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder holder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(
					R.layout.w_item_ambitus_query_result, null);
			holder = new ViewHolder();
			holder.img = (ImageView) convertView
					.findViewById(R.id.itme_ambitus_result__avatar);
			holder.name = (TextView) convertView
					.findViewById(R.id.itme_ambitus_result_name);
			holder.price = (TextView) convertView
					.findViewById(R.id.itme_ambitus_result_price);
			holder.phone = (TextView) convertView
					.findViewById(R.id.itme_ambitus_result_phone);
			holder.location = (TextView) convertView
					.findViewById(R.id.itme_ambitus_result_location);
			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		if (datas != null && !datas.isEmpty())
		{
			ScenicSpots scenic = (ScenicSpots) datas.get(position);
			String name = scenic.getName();
			String distance = String.format("%.2f", scenic.getDistance());
			holder.location.setText("约" + distance + "km");
			holder.name.setText(name);
			fb.display(holder.img, scenic.getImg());
			holder.price.setText(scenic.getPrice());
			holder.phone.setText(scenic.getPhoneNum());
		}
		return convertView;
	}

	class ViewHolder
	{
		ImageView img;
		TextView name;
		TextView location;
		TextView price;
		TextView phone;
	}
}
